/**
 * Created by TangZK on 2015/6/17.
 */

var __extends = this.__extends || function (d, b) {
		for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
		function __() {
			this.constructor = d;
		}

		__.prototype = b.prototype;
		d.prototype = new __();
	};

function generateUUID() {
	var d = new Date().getTime();
	var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
		var r = (d + Math.random() * 16) % 16 | 0;
		d = Math.floor(d / 16);
		return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
	});
	return uuid;
}
// left padding s with c to a total of n chars
function paddingLeft(str, chars, len) {
	return (new Array(len||2).join(chars||0)+(str||chars||0)).slice(-len);
}

//need moment.min.js
function friendlyTime(timestamp) {
	timestamp = timestamp || 0;
	var ftime,
		date = new Date(),
		now = date.getTime(),
		secFromNow,
		mTimestamp = parseInt(timestamp * 1000) || now;

	secFromNow = now - timestamp;

	var secDay = 3600 * 24;
	if(secFromNow < secDay) {
		ftime = moment(mTimestamp).format('H:mm:ss');
	} else if(date.getFullYear() == moment(mTimestamp).format('YYYY')) {
		ftime = moment(mTimestamp).format('MM-DD H:mm:ss');
	} else {
		ftime = moment(mTimestamp).format('YYYY-MM-DD H:mm:ss');
	}
	return ftime;
}

function json2Str(jo) {
	return JSON.stringify(jo)
}